package org.ethereum.net.dpos;

import org.ethereum.util.RLP;
import org.ethereum.util.RLPList;
import org.spongycastle.util.encoders.Hex;

public class RegisterCandidateRequest extends DPOSMessage {
	
	private final byte[] candidateId;
	
	public RegisterCandidateRequest(final byte[] encoded) {
		super(encoded);
		RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
        this.candidateId = paramsList.get(0).getRLPData();
	}
	
	public RegisterCandidateRequest(final byte[] candidate, boolean flag) {
        super(null);
        this.candidateId = candidate;
        encode();
    }
	
	private void encode() {
	     this.encoded = RLP.encodeList(RLP.encodeElement(this.candidateId));
	     this.parsed = true;
	}
	
	public byte[] getCandidateId() {
		return candidateId;
	}
	
	public String getCandidateIdStr() {
		return Hex.toHexString(candidateId);
	}

	@Override
	public DPOSMessageCodes getCommand() {
		return DPOSMessageCodes.RegisterCandidateREQUEST;
	}

	@Override
	public byte[] getEncoded() {
		return this.encoded;
	}

	@Override
	public Class<?> getAnswerMessage() {
		return RegisterCandidateResponse.class;
	}

	@Override
	public String toString() {
		return "{ candidateId: "+ Hex.toHexString(candidateId) +" }";
	}

}
